#include "stdafx.h"
#include "CADUtility.h"


CCADUtility::CCADUtility(void)
{
}


CCADUtility::~CCADUtility(void)
{
}

string CCADUtility::CStringToStdstring( CString szCStr )
{
	string sStdstr;
#ifdef _UNICODE
	int nLen = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)szCStr, -1, NULL, 0, NULL, NULL);
	if (nLen>0)
	{
		char* szAnsi = new char[nLen+1];
		ZeroMemory(szAnsi, (nLen+1)*sizeof(char));
		WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)szCStr, -1, szAnsi, nLen, NULL, NULL);
		sStdstr = string(szAnsi);
		delete []szAnsi;
	}
#else
	sStdstr = szCStr.GetBuffer(0);
#endif // _UNICODE

	return sStdstr;
}

CString CCADUtility::StdStringToCString(string sStdstr)
{
	CString szCStr=_T("");
#ifdef _UNICODE
	int nLen = MultiByteToWideChar(CP_ACP, 0, sStdstr.c_str(), -1, NULL, 0);
	if (nLen>0)
	{
		wchar_t* wcUnicode = new wchar_t[nLen+1];
		ZeroMemory(wcUnicode, (nLen+1)*sizeof(wchar_t));
		MultiByteToWideChar(CP_ACP, 0, sStdstr.c_str(), -1, wcUnicode, nLen);
		szCStr = CString(wcUnicode);
		delete []wcUnicode;
	}
#else
	szCStr = sStdstr.c_str();
#endif // _UNICODE
	return szCStr;
}